/**
 * 添加或者修改页面
 */
var StockInfoDlg = {
    data: {
        numId: "",
        qty: "",
        saleqty: "",
        ktypeId: "",
        price: "",
        costPrice: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/stock/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/stock'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });
    var loading = layer.msg('正在加载中', {icon: 16, shade: 0.3, time: 0});
    $.ajax({
        url: Feng.ctxPath + "/stock/getAllGoods",
        success: function (data) {
            var html = '<option value="" >' + "请选择" + '</option>';
            // 加载数据
            for (var i = 0; i < data.data.length; i++) {
                html += '<option value="' + data.data[i].id + '">'
                    + data.data[i].fullname + '</option>'
            }
            $("#numId").append(html);
            layer.close(loading);
            form.render();
        }
    });

    $.ajax({
        url: Feng.ctxPath + "/stock/getAllKType",
        success: function (data) {
            var html = '<option value="" >' + "请选择" + '</option>';
            // 加载数据
            for (var i = 0; i < data.data.length; i++) {
                html += '<option value="' + data.data[i].ktypeId + '">'
                    + data.data[i].fullName + '</option>'
            }
            $("#ktypeId").append(html);
            form.render();
        }
    });


    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/stock'
    });

});